<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/view/system/common/head.jsp"%>
<script type="text/javascript" src="asserts/system/js/sysUser/sysUser.js"></script>

<body>
	<table style="width: 100%; height: 100%">
		<tr>
			<td style="width: 60%; vertical-align: top;">
				<form id="form1" name="form1" method="post" action="">
					<div id="qp" class="easyui-panel" collapsible="true" style="padding:10px;">
						分组:
						<!-- <s:select id="quGroupid" class="easyui-combobox" onchange="queryDataGrid()"
							name="quGroupid" headerKey=""
							headerValue="%{pleaseSelect}" list="#request.qGroupList" listKey="id" listValue="name" style="width:100px" /> -->
						<select id="quGroupid" name="quGroupid"  class="easyui-combobox" style="width:200px;" >
						  <option value=""></option>
						  <c:forEach items="${qGroupList}" var="groupItem" >
						    <option value="${groupItem.id }">${groupItem.name }</option>
						  </c:forEach>
						</select>	
							
						<span style="margin-left:20px;">姓名或用户名:</span>
						<input class="easyui-validatebox myinput" type="text" name="quName"  maxlength="10" id="quName" style="width: 100px"></input>
                        
                      <a  class="easyui-linkbutton myLink" iconCls="icon-ok" style="margin-left:20px;"
					    onclick="queryDataGrid()">查询 </a>
					    
					    <a  class="easyui-linkbutton myLink" iconCls="icon-undo" style="margin-left:10px;"
					    onclick="restDataGrid()">重置 </a>
					</div>
					<table id="userDataGrid">
					</table>    
				</form>
			</td>
			<td style="width: 40%; vertical-align: top;">
				<iframe id="userOperatorFrame" 
					style="width: 100%; height: 100%; border:0px;" scrolling="yes">
				</iframe>
			</td>
		</tr>
	</table>
</body>
<script type="text/javascript">

$(document).ready(function() {
	setDataGridList();
});

function queryDataGrid(){
	var valid = $('#form1').form('validate');
	if (valid) {
		var param = $('#form1').serializeJson(true);
		//console.log(param);
	    $('#userDataGrid').datagrid('load', param);
	}
}

function restDataGrid(){
	$('#form1').form("reset");
	queryDataGrid();
}

/* var empStateListJSON = eval('(${empStateListJSON})'); */
var userStateListJSON = eval('(${userStateListJSON})');
/* var diplomaTypeListJSON = eval('(${diplomaTypeListJSON})'); */
//查询列表初始化
function setDataGridList() {
	$('#userDataGrid').datagrid({
		url:'user/getUserList.action',
		title:"用户列表",
		fitColumns:true,nowrap:false,rownumbers:true,showFooter:false,pagination:true,striped:true,singleSelect:false,
		idField:'id',
		tools: [{iconCls: 'icon-reload',handler: function(){$('#userDataGrid').datagrid('reload');}}],
		toolbar:[//add
		      {id:'btndisable',text:'添加',iconCls:'icon-add',handler:function(){addUser();}}
		     ,{id:'btnremove',text:'删除',iconCls:'icon-remove',handler:function(){removeBatch('userDataGrid');}}
			,{id:'btndisable',text:'禁用',iconCls:'icon-edit',handler:function(){disableBatch('userDataGrid');}}
			,{id:'btnenable',text:'启用',iconCls:'icon-edit',handler:function(){enableBatch('userDataGrid');}}
			,'-',{id:'btnSetRole',text:'换角色',iconCls:'icon-edit',handler:function(){userRoleSetBatch('userDataGrid');}}
			,{id:'btnChangeGroup',text:'换分组',iconCls:'icon-edit',handler:function(){userGroupSetBatch('userDataGrid');}}
			,'-',{id:'btnResetPassword',text:'重置密码',iconCls:'icon-edit',handler:function(){userPwdResetBatch('userDataGrid');}}
		
		],
		frozenColumns:[[
			{field:'ck',checkbox:true}
			,{field:'id',width:'1%',hidden:true,sortable:false}
			,{field:'code',title:"工号",width:'10%',sortable:true}
			,{field:'name',title:"姓名",width:'15%',sortable:true}]],
		columns:[[
			
			{field:'username',title:"用户名",width:'20%',sortable:true}
			,{field:'groupname',title:"分组",width:'20%',sortable:true}
			,{field:'rolename',title:"角色",width:'20%',sortable:true}
			,{field:'userstate',title:"用户状态",width:'10%',sortable:true,formatter:function(val){
				if(val == '0'){
					return "正常";
				}else if(val == '1'){
					return "<span style='color:red;'>已删除</>";
				}else{
					return "<span style='color:red;'>已禁用</>";
				}

			}}
		
			]],
	   onLoadSuccess: function(data){   //加载完毕后获取所有的checkbox遍历
		   $(".datagrid-header-check").html("");
		   if (data.rows.length > 0) {
              for (var i = 0; i < data.rows.length; i++) {
                if (data.rows[i].roleid == 0) {
                    $("input[type='checkbox']")[i].disabled = true;
                 }
               }
           }
       }
	  ,onClickRow: function(rowIndex, rowData){
           //加载完毕后获取所有的checkbox遍历
           $("input[type='checkbox']").each(function(index, el){
               //如果当前的复选框不可选，则不让其选中
               if (el.disabled == true) {
                   $('#userDataGrid').datagrid('unselectRow', index );
               }
           });
       }
	  
	   ,onDblClickRow: function (rowIndex, rowData) {goUserDetail(rowData.id);}  
	   ,onRowContextMenu : function(e, rowIndex, rowData) {
			e.preventDefault();
			$('#userDataGrid').datagrid('unselectAll');
			$('#userDataGrid').datagrid('selectRow', rowIndex);
			createColumnMenu(rowData);
			$('#tmenu').menu('show', {
				left : e.pageX,
				top : e.pageY
			});
		}
	});
}

var tmenu;
function createColumnMenu(rowData) {
	if (tmenu != null) {
		$("#tmenu").remove();
	}
	var menuStr = '<div id="tmenu" style="width:135px;">';
	
	if(rowData.superadmin == 0){
		menuStr += '<div data-options="iconCls:\'icon-edit\'" id="update">修改</div>';
		menuStr += '<div data-options="iconCls:\'icon-remove\'" id="delete">删除</div>';
		if (rowData.userstate == "0") {//正常
			menuStr += '<div data-options="iconCls:\'icon-edit\'"id ="forbidden">禁用</div>';
		}else if (rowData.userstate == "2") {
			menuStr += '<div data-options="iconCls:\'icon-edit\'"id ="reuse">启用</div>';
		}
	}
	
	menuStr += '<div data-options="iconCls:\'icon-ok\'" id="detail">查看详情</div>';
	menuStr += '</div>';
	tmenu = $(menuStr).appendTo('body');
	tmenu.menu( {
		onClick : function(item) {
			if (item.id == 'forbidden'){
				updateUserState('userDataGrid',rowData.id,2);
			}else if (item.id == 'reuse'){
				updateUserState('userDataGrid',rowData.id,0);
			}else if (item.id == 'update') {
				showUserUpdate(rowData.id);
			}else if (item.id == 'detail'){
				goUserDetail(rowData.id);
			}else if (item.id == 'delete'){
				removeSingle(rowData.id,'userDataGrid');
			}
		}
	});
}

var addUser = function(){
	addTab('用户添加', 'view/goViewWithoutData/user_userAdd.action', '#tt',"parent");
};


function goUserDetail(rowId){
	document.getElementById("userOperatorFrame").src = "view/goUserDetail.action?userId="+rowId;
}

function showUserUpdate(rowId){
	$.messager.alert('<s:text name="mes.message"/>', "已经打开新窗口修改用户，完成后点击确定刷新用户列表", 'info',function(){$('#userDataGrid').datagrid('reload');});
	addTab('用户修改', 'view/goUserUpdate.action?userId='+rowId, '#tt', "parent.parent");
}


/* 
function userGroupSetBatch(){
	var rows = $('#userDataGrid').datagrid('getSelections');
	if (rows.length == 0) {
		$.messager.alert('<s:text name="mes.message"/>', "请选择待操作的记录", 'info');
	} else {
		$.messager.confirm('<s:text name="mes.message"/>', "确定要更换用户的分组吗？", function(r) {
			if (r) {
				$.messager.alert('<s:text name="mes.message"/>', "已经打开新窗口设置用户分组，完成后点击确定刷新用户列表", 'info'
					,function(){$('#userDataGrid').datagrid('unselectAll');$('#userDataGrid').datagrid('reload');});
				var param = getSelections(rows);
				addTab('用户分组设置', encodeURI(encodeURI('goUserGroupSet.action'+param)), '#tt', "parent.parent");
			}
		});
	}
} */


</script>
</html>